import psycopg2

# 如果已经安装了pip，那么在命令行中输入以下命令即可完成psycopg2的安装：
#
# pip install psycopg2
# 如果提示安装失败，可以尝试在命令行中输入以下命令：
#
# pip install psycopg2-binary
db = psycopg2.connect(host="localhost", database="test", user="postgres", password="solo12345678")


def get_task_duration(userId):
    cusor = db.cursor()
    sql = 'select * from user where id = "{}"'.format(userId)
    cusor.execute(sql)
    row = cusor.fetchone()
    if row:
        duration = row[0]
    else:
        duration = 0
    return duration


duration = get_task_duration(1)
print(duration)
